<?php
require "config.php";
require "include/WeiXin.php";

$weiXin = new WeiXin($G_CONFIG['weiXin']);
$weiXin->login();
$testFakeId =  "on-DYs7fZbGDcVSiT0CbUnAeQbts";
//$testFakeId2 = "1111048821";
$time = time();
//-----------------消息编辑--------------------------------------------2015-9-1----- 
        $contentStr = "微信公众号推送消息："."\n";
        $contentStr .= "\n";
        $contentStr .= "现在是".date("Y年m月d日 H时i分",$time)."\n";
        $contentStr .= "A. 距事件A过去了XXX天\n";
        $contentStr .= "B. 距事件B过去了XXX天\n";
        $contentStr .= "C. 距事件C过去了XXX天\n";
        $contentStr .= "D. 距国庆节还有XXX天\n";
        $contentStr .= "E. 距春节还有XXX天\n";
        $contentStr .= "\n";
     

       


   print_r($weiXin->send($testFakeId,$contentStr));
  //print_r($weiXin->batSend(array($testFakeId2, $testFakeId),$contentStr));


 //--------------------------天气信息-------------------------------------------------
                            $weather = getWether('北京');
                            if($weather['errMsg'] == 'success'){
                                $contentStr  = "城市：".$weather['retData']['city']."\n";
                                $contentStr .= "日期：".$weather['retData']['date']."\n";
                                $contentStr .= "预报时间：".$weather['retData']['time']."\n";
                                $contentStr .= "天气情况：".$weather['retData']['weather']."\n";
                                $contentStr .= "最高温度：".$weather['retData']['temp']."\n";
                                $contentStr .= "最低温度：".$weather['retData']['l_tmp']."\n";
                                $contentStr .= "当前温度：".$weather['retData']['h_tmp']."\n";
                                $contentStr .= "当前风方：".$weather['retData']['WD']."\n";
                                $contentStr .= "风力大小：".$weather['retData']['WS']."\n";
                                $contentStr .= "日出时间：".$weather['retData']['sunrise']."\n";
                                $contentStr .= "日落时间：".$weather['retData']['sunset']."\n";
                                $contentStr .= "海拔：".$weather['retData']['altitude']."\n";
                                $contentStr .= "经度：".$weather['retData']['longitude']."\n";
                                $contentStr .= "纬度：".$weather['retData']['latitude']."\n";
                                
                            }
                            else{
                                $contentStr = "获取天气失败"."\n";  
                            }
	  print_r($weiXin->send($testFakeId,$contentStr));
    // print_r($weiXin->batSend(array($testFakeId2, $testFakeId),$contentStr));
 //-----------------------------------------------------------------------------


    function getWether($city='北京'){
        $ch = curl_init();
        $url = 'http://apis.baidu.com/apistore/weatherservice/cityname?cityname='.$city;
        $header = array(
            'apikey: ed6a9fca1e8a62c7685bbd882cfb659a',
        );
        // 添加apikey到header
        curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        // 执行HTTP请求
        curl_setopt($ch , CURLOPT_URL , $url);
        $res = curl_exec($ch);
        return json_decode($res,true);
   }


// echo '发送图片, 图片必须要先在公共平台中上传, 得到图片Id</br>';
// print_r($weiXin->sendImage($testFakeId, "10000001"));

// echo '批量发送</br>';

// print_r($weiXin->batSend(array($testFakeId, $testFakeId2), "test batSend"));

// echo '得到用户信息</br>';
// print_r($weiXin->getUserInfo($testFakeId));

// echo '得到最新消息，默认获取第一页消息</br>';
// $latestMsgs = $weiXin->getLatestMsgs();
// print_r($latestMsgs);
// if ($latestMsgs) {
// 	echo $latestMsgs[0]['fakeid'],'</br>';
// 	echo $latestMsgs[0]['date_time'],'</br>';
// 	echo $latestMsgs[0]['content'],'</br>';
// }

// 这个是可以得到的 只是 getLatestMsgs 这个抓取不太稳定，不能频繁去抓取
// echo '得到用户Fakeid</br>';
// $userFakeId = $weiXin->getLatestMsgByCreateTimeAndContent($createTime, $content);
// print_r($userFakeId);

// echo "开启高级模式</br>";
// $openAdvancedSwitch = $weiXin->openAdvancedSwitch('1');
// // print_r($openAdvancedSwitch);
// echo $openAdvancedSwitch['base_resp']['err_msg'] == 'ok' ? '开启成功' : '开启失败','</br>';

// echo "绑定</br>";
// $backurl = '你服务器配置的URL';
// $token = '你服务器配置的Token';
// $setCallbackProfile = $weiXin->setCallbackProfile($backurl, $token);
// // print_r($setCallbackProfile);
// echo $setCallbackProfile['ret'] === '0' ? '绑定成功' : '绑定失败','</br>';

// echo "OAuth2.0网页授权, 此功能是给服务号使用的</br>";
// $domain = '授权回调页面域名';  // 注意是不带 'http://' 的
// $changeOAuthDomain = $weiXin->changeOAuthDomain($domain);
// // print_r($changeOAuthDomain);
// echo $changeOAuthDomain['base_resp']['err_msg'] == 'ok' ? '授权回调网址修改成功' : '授权回调网址修改失败','</br>';

// echo "获取微信基本资料和认证信息appid，appkey 等</br>";
// $getWxInfo = $weiXin->getWxInfo();
// print_r($getWxInfo);